package com.lin.enumtest;

/**
 * 枚举
 */
public class EnumSetsTest {
	//基本枚举
	public enum WeekEnum{
		Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday;
		private final static String FirstDayOfWeek = "Mon";	
		public static WeekEnum getDay(){
			if("Mon".equals(FirstDayOfWeek)){
				return Monday;
			}
			return null;
		}
	}
	
	//带参数枚举
	public enum WeekAbbreviateEnum{
		Monday("Mon."),Tuesday("Tues."),Wednesday("Wed."),Thursday("Thur."),Friday("Fri."),Saturday("Sat."),Sunday("Sun.");
		public String abbr;
		public String getAbbr() {
			return abbr;
		}
		WeekAbbreviateEnum(String abbr){
			this.abbr = abbr;
		}
	}
	
	//带抽象方法的枚举
	public enum WeekChineseEnum{
		
		Monday{public String getName(){return "星期一";}},
		Tuesday{public String getName(){return "星期二";}},
		Wednesday{public String getName(){return "星期三";}},
		Thursday{public String getName(){return "星期四";}},
		Friday{public String getName(){return "星期五";}},
		Saturday{public String getName(){return "星期六";}},
		Sunday{public String getName(){return "星期日";}};
		
		public abstract String getName();
	}
	 public static void main(String[] args) {
		//枚举是一种类型，用于定义变量，以限制变量的赋值；赋值时通过“枚举名.值”取得枚举中的值 
		System.out.println("=========枚举变量值==========");
		WeekEnum weekDay = WeekEnum.Sunday;
		switch (weekDay) {
		case Monday:
			System.out.println(WeekAbbreviateEnum.Monday.abbr+WeekChineseEnum.Monday.name());
			break;
		case Sunday:
			System.out.println(WeekAbbreviateEnum.Sunday.abbr+WeekChineseEnum.Sunday.getName());		
			break;
		default:
			break;
		}
		
		//遍历枚举
		System.out.println("=========遍历枚举WeekEnum==========");
		for (WeekEnum day : WeekEnum.values()) {
			System.out.println(day);
		}
		System.out.println("=========遍历枚举WeekAbbreviateEnum============");	
		for (WeekAbbreviateEnum abbreviate : WeekAbbreviateEnum.values()) {
			System.out.println(abbreviate.abbr);
		}
		System.out.println("=========遍历枚举WeekChineseEnum============");
		for (WeekChineseEnum chinese : WeekChineseEnum.values()) {
			System.out.println(chinese.getName());
		}
		
		//获取枚举的个数
		System.out.println("========获取枚举的个数==========");
		System.out.println("WeekChineseEnum"+WeekChineseEnum.values().length);
		System.out.println("WeekEnum"+WeekEnum.values().length);
		
		//获取枚举的索引位置
		System.out.println("=========获取枚举的索引位置=============");
		System.out.println("WeekEnum.Friday："+WeekEnum.Friday.ordinal());
		System.out.println("WeekEnum.Saturday："+WeekEnum.Saturday.ordinal());
		
		//枚举默认实现了java.lang.Comparable接口  
		System.out.println("=========Comparable接口比较（返回索引差）=============");
		System.out.println(WeekEnum.Friday.compareTo(weekDay));
		System.out.println(WeekEnum.Friday.compareTo(WeekEnum.Friday));
		System.out.println(weekDay.compareTo(WeekEnum.Monday));
//		System.out.println(Week.Friday.compareTo(WeekAbbreviate.Friday));
	}
}
